package com.sunnay.util;

import lombok.Data;

import java.io.Serializable;

@Data
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;

    private String message = "请求成功";

    private long nowTime = System.currentTimeMillis();

    private T data;

    public static <T> R<T> ok(T data) {
        R<T> r = new R<T>();
        r.setCode("0");
        r.setData(data);
        r.setMessage("请求成功");
        return r;
    }

    public static <T> R<T> ok() {
        R<T> r = new R<T>();
        r.setCode("0");
        r.setData(null);
        r.setMessage("请求成功");
        return r;
    }

    public static <T> R<T> fail() {
        R<T> r = new R<T>();
        r.setCode("-1");
        r.setMessage(null);
        r.setData(null);
        return r;
    }
    public static <T> R<T> fail(String code,String message) {
        R<T> r = new R<T>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        return r;
    }

    public static <T> R<T> fail(String code,String message,T data) {
        R<T> r = new R<T>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }

}
